Test Series - java script

Test Number 5/92

Q: What will be the output of the following JavaScript code?

function output(option)
{
	return (option ?  “yes” :  “no”);
}
	bool ans=true;
console.log(output(ans));
A. Yes
B. No
C. Runtime error
D. Compilation error
Solution: “?” is called the ternary operator which is used for choosing one choice from the given two choices. It is used instead of if else statement and makes the code shorter.
Q: What will be the output of the following JavaScript code?

function height()
{	
    var  height = 123.56;
    var type = (height>=190) ? "tall" : "short";
    return type;
}
A. 123.56
B. 190
C. tall
D. short
Solution: The ternery operator is used as a comparison operator which works on three operands. The statement in the above code initializes type variable with the value short which is returned through the function.
Q: What will be the output of the following JavaScript code?

string  a = ”hi”;
string  b =”there”;
alert(a+b);
A. hi
B. there
C. hithere
D. undefined
Solution: alert function is used to print the value passed as argument in a dialog box in a browser. The alert function adds both the string and prints the result as a combined string.
Q: What will be the output of the following JavaScript code?

function output(object)
{
	var place=object ? object.place : “Italy”;
	return “clean:”+ place;
}
console.log(output({place:India}));
A. clean:India
B. clean:Italy
C. error
D. undefined
Solution: ”?” operator is used to compare the values and place is initialized according to the true condition that whether it is true or false. The function is called in the console.log and the object value is passed
Q: What will be the output of the following JavaScript code?

A. 7.25
B. -7.25
C. 7
D. -7
Solution: The abs() method returns the absolute value of a number. The method is find in the math library of Javascript.
Q: What will be the output of the following JavaScript code?

A. 125
B. 25
C. 5
D. Error
Solution: cbrt return the cubic root of a number. The method is find in the math library of Javascript.
Q: What will be the output of the following JavaScript code?

A. 1.01
B. 1.047
C. 1.00
D. 1.4
Solution: The acos() method returns the arccosine of a number as a value value between 0 and PI radians. If the parameter x is outside the range -1 to 1, the method will return NaN.
Q:  JavaScript is a _______________ language.
A. Object-Oriented
B. High-level
C. Assembly-language
D. Object-Based
Solution: JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language. The criteria for object orientation are the classic threesome of polymorphism, encapsulation and inheritance and JavaScript doesn’t pass this.
Q: What will be the output of the following JavaScript code?

var a=5 , b=1
var obj = { a : 10 }
with(obj) 
{
      alert(b)
}
A. 10
B. Error
C. 1
D. 5
Solution: Firstly the interpreter checks obj for property b. But it doesn’t find any property b so it takes the value from outside the object within the code snippet.

You Have Score    /9